/**
 * create by young (young2f@outlook.com) on 2023/4/22
 */

'use strict';
import moment from 'moment';
import {
  AutoComplete,
  Button,
  DatePicker,
  Form,
  Icon,
  Input,
  InputNumber,
  message,
  notification,
  Popconfirm,
  Popover,
  Select,
  Table,
  Upload
} from 'antd';
import ComponentBase from '../../../components/Base/ComponentBase';
import {FormField, FormLayout, ModalFooter, ModalView} from 'antd-extra';

import React from 'react';
import {connect} from 'dva';

import ViewTitle from "../../../components/ViewTitle";
import '../../index.less';
import styles from "../../index.less";
import notify from "../../../components/NotificationExtra";
import ModalSelectContacts from "./ModalSelectContacts";
import ModalCreateOrEditRentProd from "./ModalCreateOrEditRentProd";
import UploadPic from "../../../components/UploadPic";

const table = 'SalesOrder';
const {TextArea} = Input;
moment.locale('zh-cn');
@Form.create()
@connect(({global, user, dict, store}) => ({...global, ...user, ...dict, ...store}))
export default class ModalCreateOrEditRentOrder extends ComponentBase {
  constructor(props) {
    super(props);
    this.state = {};
    const {values = {}, divisionDict = []} = this.props;
    this.state = {...values};
  }

  componentDidMount() {
    const temp = this.state;
    this.onDataLoad().then(response => {
      this.setState({...temp, ...response});
    });
  }

  async onDataLoad() {
    const {values, dispatch} = this.props;
    const {code} = values;

    const lotRes = await dispatch({
      type: 'store/findOutboundLots',
      payload: {salesOrderCode: code}
    });
    let _shippingFee = 0;
    const {result = []} = lotRes;
    _.map(result, lot => {
      const {shippingFee = 0} = lot;
      _shippingFee += shippingFee;
    });
    return {lots: lotRes.result, shippingFee: _shippingFee};
  }

  renderFoot = () => {
    const {foot, value, modalRef, callback, form} = this.props;
    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {
              if (err) {
                notify({type: 'error', message: '有必填项未填写！'});
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              // _.merge(values, this.state);
              _.map(values, (value, key) => {
                if (value && value.toString().toLowerCase() === 'nan') {
                  values[key] = undefined;
                }
              });

              _.merge(this.state, values);
              callback(this.state);
              modalRef.close();
            });
          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };
  onSelectCustomer = (value, option) => {
    const {key} = option;
    this.state['customerCode'] = key;
    this.state['customer'] = value;
    const {customers, form} = this.props;
    const customer = _.find(customers, item => {
      return item.code === key;
    });
    const {contactList} = customer;
    ModalView.open(ModalSelectContacts, {
      title: "选择联系方式",
      width: '920px'
    }, {
      contacts: contactList,
      callback: data => {
        if (!data) return;
        const {address, contacts, contactsPhone} = data;
        this.state.address = address;
        this.state.contacts = contacts;
        this.state.contactsPhone = contactsPhone;
        form.setFieldsValue({address, contacts, contactsPhone});
      }
    });
  };
  getCustomerOpt = (list) => {
    const temp = [];
    _.map(list, item => {
      temp.push(<Option key={item.code} value={item.name}>
        {item.name}
      </Option>);
    });
    return temp;
    // return accounts.map(opt => (<Option key={opt.code} value={opt.accountName}>
    //     {opt.accountName + " " + opt.openingBank + " " + opt.account}
    //   </Option>
    // ));
  };

  getOrderInfo() {
    const {form, table, divisionDict,  cols = 6, customers} = this.props;
    const model = this.props[`${table}Model`];

    const taxRateOpt = model&&model.taxRate ? model.taxRate.options : [];

    const {
      code,
      division,
      address,
      contacts,
      contactsPhone,
      salesman,
      paymentWay,
      customer,

      projectName,amount,rentStartDate,rentEndDate,rentReturnDate,
      taxRate, invoiceType,
    } = this.state;
    const _taxRate = invoiceType === '不开票' ? '0%' : taxRate;
    return <FormLayout form={form} cols={cols}>
      <FormField
        label={'订单编号'}
        name={'code'}
        required={true}
        initialValue={code}
      >
        <Input style={{width: '100%'}} disabled={true}></Input>
      </FormField>
      <FormField
        label={'销售公司'}
        name={'division'}
        required={true}
        initialValue={division}
      >
        <Select allowClear placeholder="请选择" style={{width: '100%'}}
                onChange={value => {
                  this.state.division = value;
                }}
        >
          {this.getDivision(divisionDict)}
        </Select>
      </FormField>

      <FormField
        label={'项目类型'}
        name={'projectType'}
        required={true}
        initialValue={"出租"}
      >
        <Input disabled style={{width: '100%'}}></Input>
      </FormField>
      <FormField
        label={'金额'}
        name={'amount'}
        initialValue={amount}
      >
        <Input disabled style={{width: '100%'}}></Input>
      </FormField>
      <FormField
        label={'项目名称'}
        name={'projectName'}
        initialValue={projectName}
      >
        <Input style={{width: '100%'}}></Input>
      </FormField>
      <FormField
        label={'业务员'}
        name={'salesman'}
        initialValue={salesman}
      >
        <Input style={{width: '100%'}}></Input>
      </FormField>
      <FormField
        label={'结款方式'}
        name={'paymentWay'}
        initialValue={paymentWay}
      >
        <Input style={{width: '100%'}}></Input>
      </FormField>

      <FormField
        label={'发票类型'}
        name={'invoiceType'}
        initialValue={invoiceType ? invoiceType : undefined}
      >
        <Select onChange={value => this.state.invoiceType = value} allowClear style={{width: '100%'}}>
          {this.getSelectOption(model && model.invoiceType && model.invoiceType.options.length ? model.invoiceType.options : [])}
        </Select>
      </FormField>
      <FormField
        label={'税率'}
        name={'taxRate'}
        required={true}
        initialValue={_taxRate}
      >
        <Select disabled={invoiceType === '不开票'} allowClear style={{width: '100%'}}>
          {this.getSelectOption(taxRateOpt)}
        </Select>
      </FormField>

      <FormField
        label={'客户'}
        name={'customer'}
        required={true}
        initialValue={customer}
      >
        <AutoComplete style={{width: '100%'}}
                      dataSource={this.getCustomerOpt(customers)}
                      filterOption={(inputValue, option) =>
                        option.props.children.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
                      }
                      allowClear
                      onSelect={this.onSelectCustomer}
        >
        </AutoComplete>
      </FormField>
      <FormField
        label={'地址'}
        name={'address'}
        initialValue={address}
      >
        <Input style={{width: '100%'}}></Input>
      </FormField>
      <FormField
        label={'联系人'}
        name={'contacts'}
        initialValue={contacts}
      >
        <Input style={{width: '100%'}}></Input>
      </FormField>
      <FormField
        label={'联系电话'}
        name={'contactsPhone'}
        initialValue={contactsPhone}
      >
        <Input style={{width: '100%'}}
        ></Input>
      </FormField>

      <FormField
        label={'出租开始日期'}
        name={'rentStartDate'}
        required={true}
        initialValue={rentStartDate ? moment(rentStartDate) : undefined}
      >
        <DatePicker style={{width: '100%'}}
        ></DatePicker>
      </FormField>
      <FormField
        label={'出租结束日期'}
        name={'rentEndDate'}
        required={true}
        initialValue={rentEndDate ? moment(rentEndDate) : undefined}
      >
        <DatePicker style={{width: '100%'}}
        ></DatePicker>
      </FormField>
      <FormField
        label={'实际回收日期'}
        name={'rentReturnDate'}

        initialValue={rentReturnDate ? moment(rentReturnDate) : undefined}
      >
        <DatePicker style={{width: '100%'}}
        ></DatePicker>
      </FormField>
    </FormLayout>;
  }
  getFormula() {
    const {form, values} = this.props;
    const {
      mainCost = values.mainCost ? values.mainCost : 0,
      auxiliaryMaterialFee = values.auxiliaryMaterialFee ? values.auxiliaryMaterialFee : 0,
      mgrFee = values.mgrFee ? values.mgrFee : 0,
      //  shippingFee = values.shippingFee ? values.shippingFee : 0,
      unloadFee = values.unloadFee ? values.unloadFee : 0,
      publicFee = values.publicFee ? values.publicFee : 0,
      taxRate = values.taxRate ? values.taxRate : "13%", tray
    } = form.getFieldsValue();
    const {shippingFee = 0} = this.state;
    //   const {count = 0, price = 0, mainCost = 0, auxiliaryMaterialFee = 0, pkgFee = 0, mgrFee = 0, shippingFee = 0, unloadFee = 0, tray = 0, taxDeductionPointForLaborCosts = 0, publicFee = 0, laborFee = 0, taxRate = "13%"} = form.getFieldsValue();
    const {amount = 0, prods = []} = this.state;
    let _pkgFee = 0;
    let _laborFee = 0;
    let _taxDeductionPointForLaborCosts = 0;
    _.map(prods, prod => {
      const {pkgFee = 0, laborFee = 0, taxDeductionPointForLaborCosts = 0} = prod;
      _pkgFee += pkgFee;
      _laborFee += laborFee;
      _taxDeductionPointForLaborCosts += taxDeductionPointForLaborCosts;
    });
    const _rate = (parseFloat(taxRate) / 100);
    const rate = _rate + 1;
    const _valueAdderTax = ((amount - mainCost - auxiliaryMaterialFee - _pkgFee) / rate * _rate).toFixed(2);//增值
    const valueAdderTaxTitle = `增值税 =(金额-主成本-辅材-包装费用）/${rate}*${_rate}；税率为${taxRate}`;
    const laborRatioTitle = '劳务占比 = 项目奖励/金额';
    const _addedTax = (_valueAdderTax * 0.12).toFixed(2);//附加
    const addedTaxTitle = '附加税 = 增值税*0.12';
    const _stampDuty = (amount / rate * 0.0003).toFixed(2);
    const stampDutyTitle = `印花税 = 金额/${rate}*0.0003；税率为${taxRate}`;
    const _incomeTax = ((amount - mainCost - auxiliaryMaterialFee - _pkgFee) / rate * 0.05 - _addedTax - _stampDuty).toFixed(2);//所得

    const incomeTaxTitle = `所得税 =((金额-主成本-辅料-包装费用）/${rate}-附加税-印花税) *0.05；税率为${taxRate}`;
    //（(金额-主成本-辅料-包装费用)/1.13-附加税-印花税）*0.05
    const _profit = (amount - mainCost - auxiliaryMaterialFee - mgrFee - shippingFee - unloadFee - _pkgFee - tray - _taxDeductionPointForLaborCosts - publicFee - _laborFee - _valueAdderTax - _addedTax - _stampDuty - _incomeTax).toFixed(2);
    const profitTitle = `利润 = 金额-主成本-辅料-包装费用-管理费用-采购和发货运费-卸货-打包-劳务扣税点-业务招待费-项目奖励-增值税-附加税-印花税-所得税`;
    const profitTitle1 = `金额：${amount}；主成本：${mainCost}；辅材：${auxiliaryMaterialFee}；管理费：${mgrFee}；包装：${_pkgFee}；打包费用：${tray}；劳务税点：${_taxDeductionPointForLaborCosts}；业务招待费：${publicFee}；项目奖励：${_laborFee}；增值税：${_valueAdderTax}；附加税：${_addedTax}；印花税：${_stampDuty}；所得税为：${_incomeTax}；利润：${_profit} `;

    return <div>
      <p>{laborRatioTitle}</p>
      <p>{valueAdderTaxTitle}</p>
      <p>{addedTaxTitle}</p>
      <p>{stampDutyTitle}</p>
      <p>{incomeTaxTitle}</p>
      <p>{profitTitle}</p>
      <p>{profitTitle1}</p>
    </div>;
  }

  getFee() {
    const {
      shippingFee = 0,
      packageWay = "",
      auxiliaryMaterialFee = 0,
      unloadFee = 0,
      publicFee = 0,
      taxRate = "13%",amount = 0, tray, count = 0, prods = []
    } = this.state;


    let _pkgFee = 0, mainCost = 0, _laborFee = 0, _taxDeductionPointForLaborCosts = 0, _usedShippingFee = 0;
    _.map(prods, prod => {
      const {pkgFee = 0, laborFee = 0, taxDeductionPointForLaborCosts = 0, materials = []} = prod;
      _pkgFee += pkgFee;
      _laborFee += laborFee;
      _taxDeductionPointForLaborCosts += taxDeductionPointForLaborCosts;
      _.map(materials, material => {
        const {cost = 0, procureShippingFee = 0} = material;
        _usedShippingFee += procureShippingFee;
        mainCost += cost;
      });
    });
    const mgrFee = (amount * 0.08).toFixed(2);
    const _rate = (parseFloat(taxRate) / 100);
    const rate = _rate + 1;
    // const _laborRatio = laborFee ? ((laborFee / amount) * 100).toFixed(4) : 0;//劳务比例
    const _valueAdderTax = taxRate === '0%' ? 0 : ((amount - mainCost - auxiliaryMaterialFee - _pkgFee) / rate * _rate).toFixed(2);//增值税
    const _addedTax = taxRate === '0%' ? 0 : (_valueAdderTax * 0.12).toFixed(2);//附加税
    const _stampDuty = taxRate === '0%' ? 0 : (amount / rate * 0.0003).toFixed(2);//印花税
    const _incomeTax = taxRate === '0%' ? 0 : (((amount - mainCost - auxiliaryMaterialFee - _pkgFee) / rate - _addedTax - _stampDuty) * 0.05).toFixed(2);//所得税
//（(金额-主成本-辅料-包装费用)/1.13-附加税-印花税）*0.05
    let _tray = packageWay && (packageWay.includes('托盘') || packageWay.includes('吊带') || packageWay.includes('吨包')) ? (count * 0.04).toFixed(2) : tray;
    // _tray = deliverWay === '直发' ? 0 : _tray;
    _tray = _tray ? _tray : 0;
    const _profit = (amount - mainCost - auxiliaryMaterialFee - mgrFee - shippingFee - _usedShippingFee - unloadFee - _pkgFee - _tray - _taxDeductionPointForLaborCosts - publicFee - _laborFee - _valueAdderTax - _addedTax - _stampDuty - _incomeTax).toFixed(2);
    console.log('_usedShippingFee', amount, mainCost, auxiliaryMaterialFee, mgrFee, shippingFee,
      _usedShippingFee, unloadFee, _pkgFee, _tray, _taxDeductionPointForLaborCosts, publicFee, _laborFee, _valueAdderTax, _addedTax, _stampDuty, _incomeTax);

    //const _profit = (amount - mainCost - auxiliaryMaterialFee - mgrFee - shippingFee - unloadFee - _pkgFee - tray - _taxDeductionPointForLaborCosts - publicFee - _laborFee - _valueAdderTax - _addedTax - _stampDuty - _incomeTax).toFixed(2);
    const fee = {
      pkgFee: _pkgFee,
      mainCost,
      laborFee: _laborFee,
      usedShippingFee: _usedShippingFee,
      mgrFee,
      valueAdderTax: _valueAdderTax,
      addedTax: _addedTax,
      stampDuty: _stampDuty,
      incomeTax: _incomeTax,
      tray: _tray,
      profit: _profit,
      taxDeductionPointForLaborCosts: _taxDeductionPointForLaborCosts
    };
    return {fee};
  }

  getFeeInfo() {
    const {form, values, table, cols = 6} = this.props;
    const model = this.props[`${table}Model`];
    const {options} = model.taxRate;
    const {
      shippingFee = 0,
      unloadFee,
      publicFee,

      laborRatio,
      taxRate
    } = this.state;
    const {amount = 0, count = 0, prods = []} = this.state;
    const temp = this.getFee();
    const {fee = {}} = temp;
    const {
      pkgFee, laborFee,
      mainCost, usedShippingFee, taxDeductionPointForLaborCosts,
      mgrFee,
      addedTax, valueAdderTax,
      stampDuty,
      incomeTax,
      tray,
      profit
    } = fee;
    return <FormLayout form={form} cols={cols}>
      <FormField
        label={'主成本'}
        name={'mainCost'}
        initialValue={mainCost}
      >
        <InputNumber style={{width: '100%'}}
        ></InputNumber>
      </FormField>
      <FormField
        label={'管理成本'}
        name={'mgrFee'}
        initialValue={mgrFee}
      >
        <InputNumber disabled style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'发货运费'}
        name={'shippingFee'} initialValue={shippingFee}
      >
        <InputNumber disabled style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'原料运费'}
        name={'usedShippingFee'} initialValue={usedShippingFee}
      >
        <InputNumber disabled style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'卸货'}
        name={'unloadFee'} initialValue={unloadFee}
      >
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      {/*<FormField*/}
      {/*  label={'包装费用'}*/}
      {/*  name={'pkgFee'} initialValue={pkgFee}*/}
      {/*>*/}
      {/*  <InputNumber style={{width: '100%'}}*/}
      {/*  ></InputNumber>*/}
      {/*</FormField>*/}
      <FormField
        label={'打包费用'}
        name={'tray'}
        initialValue={tray}
      >
        <InputNumber style={{width: '100%'}}
        ></InputNumber>
      </FormField>
      <FormField
        label={'业务招待费'}
        name={'publicFee'}
        initialValue={publicFee}
      >
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'劳务占比 %'}
        name={'laborRatio'}
        initialValue={laborRatio}
      >
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'商品包装费用合计'}
        name={'pkgFee'}
        initialValue={pkgFee}
      >
        <InputNumber disabled style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'商品项目奖励合计'}
        name={'laborFee'}
        initialValue={laborFee}
      >
        <InputNumber disabled style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'商品劳务扣税合计'}
        name={'taxDeductionPointForLaborCosts'}
        initialValue={taxDeductionPointForLaborCosts}
      >
        <InputNumber disabled style={{width: '100%'}}></InputNumber>
      </FormField>

      <FormField
        label={'增值税'}
        name={'valueAddedTax'}
        initialValue={valueAdderTax}
      >
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'附加税'}
        name={'addedTax'}
        initialValue={addedTax}
      >
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'所得税'}
        name={'incomeTax'}
        initialValue={incomeTax}>
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'印花税'}
        name={'stampDuty'}//金额/1.13*0.0003
        initialValue={stampDuty}>
        <InputNumber style={{width: '100%'}}></InputNumber>
      </FormField>
      <FormField
        label={'利润'}//金额-主成本-辅料-管理费-运费-卸货费-包装费用-托盘费用-项目奖励税点-公关费-劳务费-增值税-附加税-所得税-印花税
        name={'profit'}
        initialValue={profit}>
        <InputNumber style={{width: '100%'}} onChange={value => {
          console.log('on change', value);
        }}></InputNumber>
      </FormField>
    </FormLayout>;
  }

  getPkgInfo() {
    const {form, values} = this.props;

    // const {
    //   packageWay = values.packageWay,
    //   deliverDate = values.deliverDate ? moment(values.deliverDate) : undefined,
    //   deliverRequire = values.deliverRequire
    // } = form.getFieldsValue();
    const {packageWay, deliverDate, deliverRequire} = this.state;
    return <FormLayout form={form} cols={1}>

      <FormField
        label={'打包方式'}
        name={'packageWay'} initialValue={packageWay}
      >
        <Input style={{width: '100%'}} allowClear></Input>
      </FormField>
      <FormField
        label={'发货要求'}
        name={'deliverRequire'} initialValue={deliverRequire}
      >
        <TextArea style={{width: '100%'}}
                  autoSize={{minRows: 3, maxRows: 5}}></TextArea>
      </FormField>
    </FormLayout>;
  }


  cols = () => {
    return [
      {title: "品名", key: "prodName", dataIndex: "prodName"},
      {title: "编号", key: "prodCode", dataIndex: "prodCode"},
      {title: "数量", key: "count", dataIndex: "count"},
      {title: "单价", key: "price", dataIndex: "price"},
      {title: "标签", key: "label", dataIndex: "label"},
      {title: "包装", key: "pkg", dataIndex: "pkg"},
      {title: "包装费用", key: "pkgFee", dataIndex: "pkgFee"},
      {title: "项目奖励", key: "laborFee", dataIndex: "laborFee"},
      {title: "劳务扣税金额", key: "taxDeductionPointForLaborCosts", dataIndex: "taxDeductionPointForLaborCosts"},
      {
        title: "开票日期", key: "invoicingDate", dataIndex: "invoicingDate", render: value => {
          return value ? <div>{moment(value).format("yyyy-MM-DD")}</div> : <div>未开票</div>;
        }
      },
      {
        title: "操作", key: "opt", dataIndex: "opt", render: (value, record) => {
          return <span>
            <a style={{marginRight: '6px'}} onClick={() => {
              ModalView.open(ModalCreateOrEditRentProd, {
                title: '编辑商品',
                width: '1080px'
              }, {
                values: record,
                callback: data => {

                  const {_code} = record;
                  const {prods = []} = this.state;
                  _.remove(prods, item => {
                    return item._code === _code;
                  });
                  data._code = _code;
                  this.state.prods.push(data);
                  this.updateProdList();
                }
              });
            }}>编辑</a>
            {
              <Popconfirm
                title="确认删除"
                onConfirm={() => {
                  let {prods = []} = this.state;
                  const {_code} = record;

                  _.remove(prods, item => {
                    return item._code === _code;
                  });
                  this.state.prods = prods;
                  this.updateProdList(record);
                }}
                okText="是"
                cancelText="否"
              >
                <a style={{marginRight: '6px'}}>删除</a>
              </Popconfirm>
            }
            </span>;
        }
      }
    ];
  };
  updateProdList = () => {
    const {form} = this.props;
    let {prods = []} = this.state;
    let amount = 0, mainCost = 0, count = 0, laborFee = 0;
    _.map(prods, item => {
      const {materials = []} = item;
      _.map(materials, it => {
        mainCost += it.cost ? parseFloat(it.cost) : 0;
      });
      const {price = 0} = item;
      laborFee += item.laborFee ? parseFloat(item.laborFee) : 0;
      count += item.count;
      amount += price * item.count;
    });
    const laborRatio = laborFee ? ((laborFee / amount) * 100).toFixed(4) : 0;//劳务比例

    form.setFieldsValue({mainCost, laborRatio});

    const temp = this.state;
    temp.prods = prods;
    temp.laborRatio = laborRatio;
    temp.amount = amount;
    temp.count = count;
    this.setState({...temp});
  };

  render() {
    const {code, memo, qsdFileList, fpFileList, fileList = [], pdfFileList = [], prods = []} = this.state;

    const {tenant} = this.getLoginInfo();
    const {tenantCode} = tenant;

    const uploadPdfButton = (
      <div>
        <Icon type="plus"/>
        <div className="ant-upload-text">上传PDF文件</div>
      </div>
    );
    return (
      <div>
        <ViewTitle
          title={'订单基础信息'}
        ></ViewTitle>
        {this.getOrderInfo()}
        <ViewTitle title={`商品列表`}
                   level={1}
                   actions={[
                     <Button type="primary" onClick={() => {
                       ModalView.open(ModalCreateOrEditRentProd, {
                         title: '添加商品',
                         width: '1080px'
                       }, {
                         callback: data => {
                           data._code = "SPD" + new Date().valueOf();
                           const {prods = []} = this.state;
                           prods.push(data);
                           this.state.prods = prods;
                           this.updateProdList();
                         }
                       });
                     }}>添加</Button>]}
        ></ViewTitle>
        <Table
          className={styles.antTable}
          bordered={true}
          columns={this.cols()}
          dataSource={prods}
          scroll={{x: true}}
          pagination={{pageSize: 100}}
          //scroll={{ x: 1300 }}
        ></Table>
        <ViewTitle
          title={'费用信息'}
          actions={<Popover content={this.getFormula()} title="公式" trigger="hover">
            <Button>查看公式</Button>
          </Popover>}
        ></ViewTitle>
        {this.getFeeInfo()}
        <ViewTitle
          title={'打包发货信息'}
        ></ViewTitle>
        {this.getPkgInfo()}
        <ViewTitle
          title={'备注'}
        ></ViewTitle>
        {
          <TextArea style={{width: '100%'}}
                    autoSize={{minRows: 3, maxRows: 5}}
                    defaultValue={memo}
                    onChange={({target: {value}}) => this.state.memo = value}
          >
          </TextArea>
        }

        <UploadPic fileList={fileList} title={'上传合同'} callback={f => this.state.fileList = f.fileList}></UploadPic>
        <UploadPic fileList={qsdFileList} title={'上传签收单'}
                   callback={f => this.state.qsdFileList = f.fileList}></UploadPic>
        <UploadPic fileList={fpFileList} title={'上传发票'}
                   callback={f => this.state.fpFileList = f.fileList}></UploadPic>
        {
          //上传PDF
          <div style={{marginLeft: '64px'}}>
            <Upload
              name={'file'}
              action={`http://127.0.0.1:18008/api/global/upload?orderCode=${code}&table=SalesOrder&tenantCode=${tenantCode}&fileList=${[...pdfFileList]}`}
              headers={{authorization: 'authorization-text'}}
              listType={"picture-card"}
              accept={".pdf"}
              fileList={pdfFileList}
              showUploadList={true}
              // previewFile={file=>{
              //   console.log(file);
              // }}
              onDownload={info => {
                console.log('ondownlad', info);
              }}
              onPreview={file => window.open(file.url)}
              onChange={(info) => {
                let {fileList} = info;
                fileList = fileList.filter(file => file.type === 'application/pdf');
                fileList = fileList.map(file => {
                  if (file.response) {
                    file.url = file.response.result.url; // 假设服务端返回了文件url
                  }
                  return file;
                });
                const temp = this.state;
                temp.pdfFileList = fileList;
                this.setState({...temp});

              }}
              // 限制文件类型为PDF
              beforeUpload={file => {
                const isPdf = file.type === 'application/pdf';
                if (!isPdf) {
                  message.error('只可以上传 PDF 文件!');
                }
                return isPdf;
              }}
            >
              {uploadPdfButton}
            </Upload>
          </div>}
        {this.renderFoot()}
      </div>
    );
  }
}

